package com.kedacom.demo.websocket.rpc;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class PendingRequestHolder {

	private volatile static PendingRequestHolder singleton;
	private static Map<String, PendingRequest> pendingRequests;

	private PendingRequestHolder() {
	}

	public static PendingRequestHolder getInstance() {
		if (singleton == null) {
			synchronized (PendingRequestHolder.class) {
				if (singleton == null) {
					singleton = new PendingRequestHolder();
					pendingRequests = new ConcurrentHashMap<String, PendingRequest>();
				}
			}
		}
		return singleton;
	}

	public void put(String requestId, PendingRequest pendingRequest) {
		pendingRequests.put(requestId, pendingRequest);
	}

	public PendingRequest get(String requestId) {
		return pendingRequests.get(requestId);
	}

	public PendingRequest remove(String requestId) {
		return pendingRequests.remove(requestId);
	}

}
